package boddaert.philippe.cashGame.net;

import java.io.IOException;
import java.net.URL;
import java.util.Properties;

import org.apache.log4j.Logger;

public class DefaultWebPageGetterFactory {

	private static final String APPLICATION_PROPERTIES = "application.properties";

	private static final String WEB_PAGE_PARSER_FACTORY_TYPE = "webPageParserFactory.type";

	private final static Logger logger = Logger
			.getLogger(DefaultWebPageGetterFactory.class);

	public static Properties getProperties() throws IOException {
		Properties properties = new Properties();
		URL applicationProperties = ClassLoader
				.getSystemResource(APPLICATION_PROPERTIES);
		logger.debug(applicationProperties.getPath());
		properties.load(applicationProperties.openStream());
		return properties;
	}

	public static Net getFactoryType() throws IOException {
		Properties properties = getProperties();

		if (properties.containsKey(WEB_PAGE_PARSER_FACTORY_TYPE))
			return Net.valueOf((String) (properties
					.get(WEB_PAGE_PARSER_FACTORY_TYPE)));
		return null;
	}

	public static WebPageGetter get() throws IOException {
		return WebPageGetterFactory.get(getFactoryType());
	}

}
